package com.yibing.plat;

import java.util.Date;
import java.util.concurrent.LinkedBlockingQueue;



public class Logger implements Runnable{
	
	private Logger(int queLength) {
		queue = new LinkedBlockingQueue<String>(queLength);
	}
	
	public static void start() {
		Thread t = new Thread(inst);
		t.start();
	}
	
	public static void log(String s) {
		try {
			inst.queue.put(s);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void run() {
		try {
			while (true) {
				String msg = queue.take();
				System.out.println("[" + new Date() + "] " + msg);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	private LinkedBlockingQueue<String> queue;
	
	private static Logger inst = new Logger(1024);

	
}
